package com.example.lib5.company_interface.StringsAndArrays.testB;

/**
 * 创建日期：2022/6/10 0010 2:09
 *
 * @author tony.sun
 * 类说明：
 */
public class StringOperateImplB implements IStringOperateB {
    @Override
    public String[] split(String str, String divide) {
        String[] res=new String[str.length()];
        int index=0;
        while (true) {
            if (str.contains(divide)){
                int idf = str.indexOf(divide);
                res[index++]=str.substring(0,idf);
                str=str.substring(idf+2);
            }else {
                res[index]=str;
                break;
            }
        }
        return res;
    }

    @Override
    public String group(String[] strs, String divide) {
        StringBuilder sb=new StringBuilder();
        for (String str : strs) {
            sb.append(str);
            sb.append(divide);
        }
        sb.delete(sb.length()-2,sb.length());
        return sb.toString();
    }
}
